<?

require_once(dirname(__FILE__) . '/../config/config.inc.php');
if ($_POST) {
    $id = $_POST['id'];
    $category = $_POST['category'];
    $plan = $_POST['plan'];
    $type = $_POST['type'];
    if (strtolower($category) == 'v') {
        if ($type == 'J') {
            $data = array('id_plan' => $plan);
            DbSet::enterprises($data, $id);
            echo "OK";
        }
    } else if (strtolower($category) == 'p') {
        if ($type == 'J') {
            $data = array('id_product_plan' => $plan);
            DbSet::enterprises($data, $id);
            $data2 = array(
                'id_client' => $id,
                'id_status' => 1,
                'type' => 'J'
            );
            DbSet::products_client_status($data2);
            $data3 = array(
                'id'=>"m_".md5(time()),
                'id_client' => $id,
                'type' => 'J'
            );
            DbSet::products_client_status($data3);
            echo "OK";
        } else if ($type == 'F') {
            $data = array('id_product_plan' => $plan);
            DbSet::customers($data, $id);
            $data2 = array(
                'id_client' => $id,
                'id_status' => 1,
                'type' => 'F'
            );
            DbSet::products_client_status($data2);
            $data3 = array(
                'id'=>"m_".md5(time()),
                'id_client' => $id,
                'type' => 'J'
            );
            DbSet::products_client_status($data3);
            echo "OK";
        }
    } else {
        echo "ERRO";
    }
}
?>
